package com.example.lianxi1.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.lianxi1.AlbumsBean;
import com.example.lianxi1.Bean;
import com.example.lianxi1.R;

import java.util.ArrayList;
import java.util.List;

public class ListAdapter extends RecyclerView.Adapter<ListAdapter.Holder> {
    public Context context;

    public ListAdapter(Context context) {
        this.context = context;
    }
    public List<AlbumsBean> list=new ArrayList<>();

    public void addList(List<AlbumsBean> list) {
        this.list.addAll(list);
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.layout_item, parent, false);
        return new Holder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int position) {
        AlbumsBean albumsBean = list.get(position);
        Glide.with(context).load(albumsBean.getImage_url()).into(holder.image);
        holder.name.setText(albumsBean.getName());
        holder.desc.setText(albumsBean.getDescription());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    public class Holder extends RecyclerView.ViewHolder {

        private final ImageView image;
        private final TextView desc;
        private final TextView name;

        public Holder(@NonNull View itemView) {
            super(itemView);
            image = itemView.findViewById(R.id.item_image);
            name = itemView.findViewById(R.id.item_name);
            desc = itemView.findViewById(R.id.item_desc);
        }
    }
}
